package com.xuzimian.globaldemo.quartz.job;

import com.xuzimian.globaldemo.quartz.util.SchedulerHelper;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class UseSpringBeanJob  implements Job {

    @Resource
    private SimpleBean simpleBean;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("----- " + jobExecutionContext.getJobDetail().getKey().getName() + " 执行任务了 -----");
        System.out.println(this);
        try {
            SchedulerHelper.removeJob(jobExecutionContext.getJobDetail().getKey().getName(), jobExecutionContext.getJobDetail().getKey().getGroup());

            simpleBean.doSomething();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
